package com.xiaoma.mframe.project.tool.gen.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xiaoma.mframe.general.utils.AjaxResult;
import com.xiaoma.mframe.general.web.controller.BaseController;
import com.xiaoma.mframe.general.web.page.TableDataInfo;
import com.xiaoma.mframe.project.tool.gen.entity.Template;
import com.xiaoma.mframe.project.tool.gen.service.ITemplateService;

/**
 * 模板 信息操作处理
 * @author machuxin
 * @date 2018-11-26
 */
@Controller
@RequestMapping("/system/template")
public class TemplateController extends BaseController
{
    private String prefix = "system/template";
	
	@Autowired
	private ITemplateService templateService;
	
	@GetMapping()
	public String template()
	{
	    return prefix + "/template";
	}
	
	/**
	 * 查询模板列表
	 */
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Template template)
	{
		startPage();
        List<Template> list = templateService.selectTemplateList(template);
		return getDataTable(list);
	}
	
	/**
	 * 新增模板
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存模板
	 */
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Template template)
	{		
		return toAjax(templateService.insertTemplate(template));
	}

	/**
	 * 修改模板
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		Template template = templateService.selectTemplateById(id);
		mmap.put("template", template);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存模板
	 */
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Template template)
	{		
		return toAjax(templateService.updateTemplate(template));
	}
	
	/**
	 * 删除模板
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(templateService.deleteTemplateByIds(ids));
	}
	
}
